package com.qf.zhijia.zhijiasearch.controller;

import com.qf.zhijia.zhijiasearch.pojo.Product;
import com.qf.zhijia.zhijiasearch.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 岳鹏
 * @Date 2020/9/9
 */
@RestController
@RequestMapping("/zhijiaSearch")
public class SearchController  {

    @Autowired
    SearchService searchService;

    /**
     * ES搜索
     * @param pName
     * @return
     */
    @PostMapping("/SerchPro")
    public String search(@RequestBody String pName){
        System.out.println("你输入了查询的值："+pName);
        try {
            return searchService.search(pName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * ES增加
     */
    @PostMapping("/add")
    public void add(@RequestBody Product product){
        System.out.println("ES的Controller开始操作同步数据");
        try {
            searchService.add(product);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
